package com.depot.auth.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.depot.auth.dao.ResIconDao;
import com.depot.domains.ResIcon;
import com.opensymphony.xwork2.ModelDriven;
import com.soar.BaseActionSupport;
import com.soar.context.Environment;

/**
 * 
 * @author Gravey Quen
 * @version $Revision$ - $Author$ at $Date$
 * @description com.itaskstar.auth.web.ResIconAction
 */
@SuppressWarnings("serial")
public class ResIconAction extends BaseActionSupport implements ModelDriven<ResIcon>
{
	private ResIcon domain = new ResIcon();

	public List<HashMap<String, String>> icongroup = new ArrayList<HashMap<String, String>>();
	
	public List<HashMap<String, String>> icongroupall = new ArrayList<HashMap<String, String>>();

	public String execute(Environment env) throws Exception
	{
		this.icongroup = ResIconDao.selectGroup(env, domain);
		this.sysPageList = ResIconDao.select(env, domain, this);
		return "res_icon_list";
	}

	public String doNew(Environment env) throws Exception
	{
		return "res_icon_edit";
	}

	public String doInsert(Environment env) throws Exception
	{
		String res = ResIconDao.doInsert(env, domain);
		if ("1".equals(res))
		{
			this.setMessage("保存成功！", env, true);
		}
		else
		{
			this.setMessage("保存失败，请重试！", env, false);
		}
		return null;
	}

	public String doSave(Environment env) throws Exception
	{
		String res = ResIconDao.doSave(env, domain);
		if ("1".equals(res))
		{
			this.setMessage("保存成功！");
		}
		else
		{
			this.setMessage("保存失败，请重试！");
		}
		return this.execute(env);
	}

	public String doDelete(Environment env) throws Exception
	{
		String[] ids = new String[1];
		if (domain.getIds() != null)
		{
			ids = new String[domain.getIds().length];
			for (int i = 0; i < domain.getIds().length; i++)
			{
				ids[i] = domain.getIds()[i].split("_")[0];
			}
		}
		else
		{
			ids[0] = domain.getId();
		}
		String res = ResIconDao.dodelete(env, ids);
		if ("1".equals(res))
		{
			this.setMessage("删除成功！");
		}
		else
		{
			this.setMessage("删除失败，请重试！");
		}
		return this.execute(env);
	}

	public String getGroup(Environment env) throws Exception
	{
		this.icongroup = ResIconDao.selectGroup(env, domain);
		env.getResponse().getWriter().print(this.icongroup);
		return null;
	}
	
	public String selIcon(Environment env)throws Exception
	{
		this.icongroupall = ResIconDao.selectGroup(env, new ResIcon());
		this.icongroup = ResIconDao.selectGroup(env, domain);
		this.sysPageList = ResIconDao.select(env, domain);
		return "ajax_iconlist";
	}

//	public String indata(Environment env) throws Exception
//	{
//		String s = "ambulance,fa fa-h-square,fa fa-heart,fa fa-heart-o,fa fa-heartbeat,fa fa-hospital-o,fa fa-medkit,fa fa-plus-square,fa fa-stethoscope,fa fa-user-md,fa fa-wheelchair,fa fa-wheelchair-alt";
//		String group = "医疗";
//		ResIconDao.indata(env, s.split(","), group);
//		return this.execute(env);
//	}

	public ResIcon getModel()
	{
		return this.domain;
	}
}
